package MyFragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.qb.devtest.MyApplication;
import com.qb.devtest.R;

import java.util.Date;

import utils.MyUtil;

public class FragmentCashbox extends Fragment {
    Context ctx = MyApplication.getInstance();
    Button cashboxOpen;
    TextView cashboxInfo;
    String cashboxInfoStr = "";

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_cashbox, container, false);

        cashboxInfo = view.findViewById(R.id.cashbox_info);

        cashboxOpen = view.findViewById(R.id.cashbox_open);
        cashboxOpen.setOnClickListener(view1 -> {
            Intent intent = new Intent("android.intent.action.CASHBOX");
            intent.putExtra("cashbox_open", true);
            ctx.sendBroadcast(intent);

            cashboxInfoStr = cashboxInfoStr + MyUtil.formatDateTime(new Date()) +" 开钱箱指令已发送，请查看钱箱是否已开启\n";
            cashboxInfo.setText(cashboxInfoStr);
        });
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // 在这里初始化你的Fragment视图组件
    }
}